package com.hog.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;

import java.util.HashMap;
import java.util.Map;

/**
 * 系统初始化
 *
 * @author 糖先森
 * @date 2018年04月05日
 * @since JDK 1.8
 */
@Component
public class WebInitialization implements EnvironmentAware {
    private final static String themes = "insdep";
    @Value("${spring.application.name}")
    private String applicationName;

    @Override
    public void setEnvironment(Environment environment) {
    }
    
    @Autowired
    private void configureThymeleafStaticVars(ThymeleafViewResolver viewResolver) {
        if (viewResolver != null) {
            Map<String, Object> vars = new HashMap<>();
            vars.put("themes", themes);
            vars.put("applicationName", applicationName);
            viewResolver.setStaticVariables(vars);
        }
    }
}